package slap.http.websocket;

import com.google.gson.Gson;

public abstract class Outbound {

	public static ThreadLocal<Outbound> current = new ThreadLocal<Outbound>();

	public static Outbound current() {
		return current.get();
	}

	public abstract void send(String data);

	public abstract void send(byte opcode, byte[] data, int offset, int length);

	public abstract boolean isOpen();

	public abstract void close();

	public void send(byte opcode, byte[] data) {
		send(opcode, data, 0, data.length);
	}

	public void send(String pattern, Object... args) {
		send(String.format(pattern, args));
	}

	public void sendJson(Object o) {
		send(new Gson().toJson(o));
	}
}